/*
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 */
package com.l2jserver.gameserver.faction;

import java.util.Collection;
import java.util.Map;

import javolution.util.FastMap;

import com.l2jserver.gameserver.model.L2Object;
import com.l2jserver.gameserver.model.actor.L2Npc;
import com.l2jserver.gameserver.model.actor.instance.L2FClanFlagInstance;
import com.l2jserver.gameserver.model.actor.instance.L2FactionCrystalInstance;
import com.l2jserver.gameserver.templates.StatsSet;
import com.l2jserver.gameserver.util.Util;

/**
 * @author Laikeriz
 */
public class FactionMap
{
	public int id = 0;
	public Map<Integer, StatsSet> flags = new FastMap<Integer, StatsSet>();
	public Map<Integer, L2FactionCrystalInstance> spawnedFlags = new FastMap<Integer, L2FactionCrystalInstance>();
	public Map<Integer, L2FClanFlagInstance> clanFlags = new FastMap<Integer, L2FClanFlagInstance>();
	public Map<Integer, String> doorsToOpen = new FastMap<Integer, String>();
	public L2Object clanFlagCenter = null;
	public StatsSet clanFlagConf = new StatsSet();
	public String name = "";
	
	public FactionMap(String _name, int _id)
	{
		name = _name;
		id = _id;
	}
	
	public void addFlag(int id, StatsSet flag)
	{
		flags.put(id, flag);
	}
	
	public boolean existsClanFlag(int objId)
	{
		return clanFlags.containsKey(objId);
	}
	
	public void addClanFlag(L2FClanFlagInstance flag, int objId)
	{
		clanFlags.put(objId, flag);
	}
	
	public void addSpawnedFlag(L2FactionCrystalInstance flag, int flagId)
	{
		spawnedFlags.put(flagId, flag);
	}
	
	public String getName()
	{
		return name;
	}
	
	public int getId()
	{
		return id;
	}
	
	public Collection<StatsSet> getFlags()
	{
		return flags.values();
	}
	
	public Map<Integer, L2FactionCrystalInstance> getSpawnedFlags()
	{
		return spawnedFlags;
	}
	
	public L2FactionCrystalInstance getSpawnedFlag(int id)
	{
		return spawnedFlags.get(id);
	}
	
	public L2Npc getFlagById(int id)
	{
		return spawnedFlags.get(id);
	}
	
	public boolean canSpawnClanFlag(L2Object player)
	{
		if (!clanFlagConf.getBool("canBeSpawned") || clanFlagConf.getInteger("centerX") == 0 || clanFlagConf.getInteger("centerY") == 0 || clanFlagConf.getInteger("centerZ") == 0 || clanFlagConf.getInteger("radius") == -1)
			return false;
		if (Util.checkIfInShortRadius(clanFlagConf.getInteger("radius"), clanFlagCenter, player, false))
			return true;
		
		return false;
	}
}
